﻿using System.Web;
using System.Xml.Serialization;
using Newtonsoft.Json;

namespace Samples.WebService.Models
{
    [XmlRoot(ElementName = "Error")]
    public class ErrorDetail
    {
        private string _debugInformation;

        // Default constructor still required for the serializer
        public ErrorDetail()
        {
            Description = string.Empty;
        }

        public ErrorDetail(string description = "", string debugInformation = "")
        {
            Description = description;
            DebugInformation = debugInformation;
        }

        [XmlElement("Description"), JsonProperty(PropertyName = "description")]
        public string Description { get; set; }

        [XmlElement("DebugInformation"), JsonProperty(PropertyName = "debugInformation")]
        public string DebugInformation
        {
            get
            {
                return HttpContext.Current.IsDebuggingEnabled ? _debugInformation : null;
            }

            set
            {
                _debugInformation = value;
            }
        }

        [JsonIgnore, XmlIgnore]
        public bool DebugInformationSpecified { get { return !string.IsNullOrWhiteSpace(DebugInformation); } set { } } // do not delete set as the JsonSerializer doesn't like it
    }
}